﻿// $Id: Exceptions.cs 10 2008-02-29 15:58:02Z mcartoixa $

/* ***************************************************************************
 *                                                                           *
 * Copyright © 2007 NourY Solutions                                          *
 *                                                                           *
 * This file is part of DataRules.                                           *
 *                                                                           *
 * DataRules is free software; you can redistribute it and/or modify it      *
 * under the terms of the GNU Lesser General Public License as published     *
 * by the Free Software Foundation; either version 3 of the License, or      *
 * (at your option) any later version.                                       *
 *                                                                           *
 * DataRules is distributed in the hope that it will be useful, but          *
 * WITHOUT ANY WARRANTY; without even the implied warranty of                *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU          *
 * Lesser General Public License for more details.                           *
 *                                                                           *
 * You should have received a copy of the GNU Lesser General Public          *
 * License along with this program.  If not, see                             *
 * <http://www.gnu.org/licenses/lgpl.html>.                                  *
 *                                                                           *
 *************************************************************************** */

/*! \file
 * \brief Definition of \c Salamanca.DataRules.BrokenRulesException.
 *
 * \author $Author: mcartoixa $
 * \date $Date: 2008-02-29 16:58:02 +0100 (ven., 29 févr. 2008) $
 * \version $Revision: 10 $
 */

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
#if (!NET_CF)
using System.Runtime.Serialization;
#endif

namespace Salamanca.DataRules
{



    ///////////////////////////////////////////////////////////////////////////
    ///
    /// <summary>Exception related to broken business rules.</summary>
    ///
    ///////////////////////////////////////////////////////////////////////////

#if (!NET_CF)
    [Serializable]
#endif
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2240:ImplementISerializableCorrectly")]
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1032:ImplementStandardExceptionConstructors")]
    public sealed class BrokenRulesException:
        Exception
    {

        /// <summary>Initializes a new instance of the <see cref="BrokenRulesException"/> class.</summary>
        /// <param name="brokenRule">The broken rule the exception is created for.</param>
        /// <param name="invalidInstance">The instance that broke the specified rule.</param>
        public BrokenRulesException(IRule brokenRule, IValidatable invalidInstance):
            this(new IRule[] { brokenRule }, invalidInstance)
        {
        }

        /// <summary>Initializes a new instance of the <see cref="BrokenRulesException"/> class.</summary>
        /// <param name="brokenRules">The broken rules the exception is created for.</param>
        /// <param name="invalidInstance">The instance that broke the specified rules.</param>
#if (NET_1_0 || NET_1_1 || NET_CF_1_0)
        public BrokenRulesException(IEnumerable brokenRules, IValidatable invalidInstance):
#else
        public BrokenRulesException(IEnumerable<IRule> brokenRules, IValidatable invalidInstance):
#endif
            base(Rules.GetMessage(brokenRules))
        {
            _InvalidInstance=invalidInstance;
        }

#if (!NET_CF)
        /// <summary>Initializes a new instance of the <see cref="BrokenRulesException"/> class.</summary>
        /// <param name="info">The <see cref="SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param>
        /// <param name="context">The <see cref="StreamingContext" /> that contains contextual information about the source or destination.</param>
        private BrokenRulesException(SerializationInfo info, StreamingContext context):
            base(info, context)
        {
        }
#endif

        /// <summary>The instance that broke the rules.</summary>
        public IValidatable InvalidInstance
        {
            get
            {
                return _InvalidInstance;
            }
        }

        /// <summary>The instance that broke the rules.</summary>
        private IValidatable _InvalidInstance;

    }

}
